package org.btik.light.mobile.common.handler;

import android.view.View;
import org.btik.light.mobile.meta.mo.DefaultDevMo;

import java.util.List;
import java.util.function.BiConsumer;

/**
 * @author lustre
 * @since 2023/4/30 17:52
 */
public class SimpleSpeedController extends CmdSender implements BiConsumer<Integer, View>, DevBinder {

    private final SimpleCommand ctrlCommand;

    public SimpleSpeedController(int opcode, String... param) {
        this.ctrlCommand = new SimpleCommand(opcode, param);
    }

    @Override
    public void accept(Integer integer, View view) {
        if (integer == null) {
            return;
        }
        List<Object> params = (List<Object>) ctrlCommand.getParams();
        params.set(1, integer.toString());
        send(view.getContext(),  ctrlCommand);
    }

    @Override
    public void bind(DefaultDevMo devMo) {
        ctrlCommand.setTarget(devMo.getSn());
    }
}
